package com.example.ccj.b.c.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import androidx.annotation.NonNull;

import com.example.ccj.R;
import com.example.ccj.b.c.recycler.BaseRecycler;
import com.example.ccj.b.c.recycler.DefaultAdapterOnBind;
import com.example.ccj.u.ImageUtils;
import com.example.ccj.u.StringUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * 底部弹出功能列表
 * @author 驰珺
 * whechat   : chijun9
 * create at : 2024/5/14 9:27
 */
public class BottomFunctionDialog extends DialogBase {

    BaseRecycler<FunctionMode> functionModeBaseRecycler;
    List<FunctionMode> functionModeList;


    public BottomFunctionDialog(@NonNull Context context) {
        super(context);
        functionModeList = new ArrayList<>();
    }

    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_bottom_function);
        setAlpha(1f);//透明度
        isCanClose(true);//点击允许关闭
        isShowBackground(true);//不显示背景
        setHeightRatio(0.5);//高度显示比例
        showInBottom();//中间弹出
        setFull(true);//占满宽度

        functionModeBaseRecycler = findViewById(R.id.dialog_bottom_function_rec);
        functionModeBaseRecycler.setDefaultAdapter(functionModeList, R.layout.adapter_bottom_function, new DefaultAdapterOnBind<FunctionMode>() {
            @Override
            public View onBind(View view, FunctionMode data) {
                TextView text = view.findViewById(R.id.adapter_bottom_function_text);
                text.setText(data.name);
                if (data.color > 0) text.setTextColor(data.color);
                if (!StringUtils.isEmpty(data.img)) {
                    ImageView imageView = view.findViewById(R.id.adapter_bottom_function_img);
                    ImageUtils.loadImage(getContext(),data.img,imageView);
                }
                view.setOnClickListener(data.onClickListener);
                return view;
            }
        });
    }


    public void setFunction(String name,View.OnClickListener onClickListener){
        FunctionMode functionMode = new FunctionMode(name,onClickListener);
        functionModeList.add(functionMode);
//        functionModeBaseRecycler.addDataOnHead(functionMode);
    }

    public void setFunction(String name, int color, View.OnClickListener onClickListener){
        FunctionMode functionMode = new FunctionMode(name,onClickListener);
        functionMode.color = color;
        functionModeList.add(functionMode);
//        functionModeBaseRecycler.addDataOnHead(functionMode);
    }


    static class FunctionMode{
        public FunctionMode(String name,View.OnClickListener onClickListener){
            this.name = name;
            this.onClickListener = onClickListener;
        }
        int color;
        String name;
        String img;
        View.OnClickListener onClickListener;
    }



}
